package app

import (
	"gitee.com/ling1314/origin-utility/middleware"
	"gitee.com/ling1314/origin-utility/modules/api"
	"github.com/gin-gonic/gin"
	"net/http"
)

func setupRoutes() *gin.Engine {
	r := gin.New()
	//gin.SetMode(gin.ReleaseMode) //使用 release 模式运行，

	r.Use(gin.Recovery(), middleware.LoggerError())
	r.Static("/static", "./static")
	var testApi = api.TestApi
	publicGroup := r.Group("")
	{
		// 健康监测
		publicGroup.GET("/health", func(c *gin.Context) {
			c.JSON(200, "ok")
		})
		publicGroup.POST("upload", testApi.FileUpload)
		publicGroup.POST("orgPic", api.IdpOrgApi.SavePlantPic2)
		publicGroup.POST("login", api.UserApi.Login)
	}
	publicGroup.GET("/gua/tunnel", api.GuaApi.WSConnect)
	publicGroup.GET("/gua/monitor", api.GuaApi.Monitor)
	PrivateGroup := r.Group("").Use(middleware.GinAuthorizationMiddleAware())
	{
		PrivateGroup.GET("test", func(c *gin.Context) {
			c.JSON(200, "user")
		})
		// 路由树
		PrivateGroup.GET("getRouterTreeForFile", api.UserApi.GetRouterTreeForFile)

		// 用户管理
		PrivateGroup.POST("/user", api.UserApi.Add)
		PrivateGroup.PUT("/user", api.UserApi.Update)
		PrivateGroup.GET("/user", api.UserApi.Page)
		PrivateGroup.DELETE("/user/:id", api.UserApi.Delete)
		PrivateGroup.PUT("/resultPwd", api.UserApi.ResultPwd)
		PrivateGroup.GET("self", api.UserApi.GetSelfDetail)
		PrivateGroup.GET("/user/:id", api.UserApi.Detail)
		PrivateGroup.GET("/getPublicRoles", api.UserApi.GetPublicRoles)
		PrivateGroup.GET("/getUserList/:id", api.UserApi.GetUserListByDeptId)

		// 组织管理
		PrivateGroup.POST("/dept", api.DeptApi.Add)
		PrivateGroup.PUT("/dept", api.DeptApi.Update)
		PrivateGroup.GET("/dept", api.DeptApi.FindAll)
		PrivateGroup.DELETE("/dept/:id/:del", api.DeptApi.Delete)

		// 角色管理

		// 集群管理
		PrivateGroup.GET("/cluster", api.ClusterApi.FindAll)
		PrivateGroup.POST("/cluster", api.ClusterApi.Add)
		PrivateGroup.PUT("/cluster", api.ClusterApi.Update)
		PrivateGroup.DELETE("/cluster/:id", api.ClusterApi.Delete)
		PrivateGroup.PUT("/moveHost", api.ClusterApi.MoveHost)

		// 应用
		PrivateGroup.GET("/getAppInstallList/:id", api.AppApi.GetAppInstallList)
		PrivateGroup.POST("/checkIssueStatus", api.AppApi.CheckIssueStatus)
		PrivateGroup.POST("/issueApp", api.AppApi.IssueApp)
		PrivateGroup.GET("/getSelfAppList", api.AppApi.GetSelfAppList)     // 客户端用户获取自己的应用列表
		PrivateGroup.GET("/getAppInfo/:id", api.AppApi.GetAppIssueInfo)    // 获取应用详情
		PrivateGroup.GET("/app/getIssueList", api.AppApi.GetIssueList)     // 获取应用
		PrivateGroup.DELETE("/app/deleteIssue", api.AppApi.DeleteIssueApp) // 删除已经发布的应用

		// 主机
		PrivateGroup.GET("/host", api.HostApi.Page)
		PrivateGroup.GET("/host/list", api.HostApi.List)
		PrivateGroup.GET("/host/detail/:id", api.HostApi.Details)

		// 会话
		PrivateGroup.GET("/checkReuse", api.GuaApi.CheckSessionReuse)
		PrivateGroup.GET("/createSession", api.GuaApi.CreateSession)
		PrivateGroup.POST("/bindWinSession", api.GuaApi.BindWinSessionId)
		PrivateGroup.POST("/insertAppOpenLog", api.GuaApi.InsertAppOpenLog)
		PrivateGroup.GET("/getSessionPageForAdmin", api.GuaApi.GetSessionPageForAdmin)
		PrivateGroup.POST("/logoff/:id", api.GuaApi.Logoff)
		PrivateGroup.POST("/break/:id", api.GuaApi.Break)
		PrivateGroup.POST("/sendInstruct", api.GuaApi.SendInstruct)

		// 拓扑图
		PrivateGroup.POST("/topo", api.SettingApi.SaveTopology)
		PrivateGroup.GET("/topo", api.SettingApi.GetTopology)

		// miao 客户端基础接口
		PrivateGroup.GET("/miao/win/page", api.DeviceApi.Page)
		PrivateGroup.GET("/miao/win/detail", api.DeviceApi.Detail)
		PrivateGroup.POST("/miao/sendInstruct", api.DeviceApi.SendInstruct)
		PrivateGroup.GET("/miao/win/getLog", api.DeviceApi.GetLog)

		// org 模块下的关联接口
		PrivateGroup.GET("/org/GetOrgList", api.IdpOrgApi.GetOrgList)
		PrivateGroup.GET("org/devices/:id", api.DeviceApi.GetListByOrgId)
		PrivateGroup.POST("/org/SavePlantPic", api.IdpOrgApi.SavePlantPic)
		PrivateGroup.POST("/org/UpdateOrg", api.IdpOrgApi.UpdateOrg)
		PrivateGroup.POST("/org/SavePoint", api.IdpOrgApi.SavePoint)
		PrivateGroup.GET("/org/GetPoint/:id", api.IdpOrgApi.GetPoint)
		PrivateGroup.GET("/org/GetMapJson/:code", api.IdpOrgApi.GetMapJson)

		PrivateGroup.POST("/miao/client/distribute", todo)

	}
	return r
}

// todo 还没想好的接口占位符
func todo(ctx *gin.Context) {
	ctx.JSON(http.StatusCreated, "todo")
}
